﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using SgAutoArchiveBrrDal;
using SgAutoArchiveBrrDal.Linq;

namespace SgAutoArchiveSp.Dialog
{
    public partial class Dialog_Login : DevExpress.XtraEditors.XtraForm
    {
        public bool _bOK = false;
        public Dialog_Login()
        {
            InitializeComponent();
            txt_UName.Focus();
        }

        private void txt_UName_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                txt_Pwd.Focus();
        }

        private void btn_Login_Click(object sender, EventArgs e)
        {
            var en = T_USER_Dal.Get_LoginUser(txt_UName.Text, txt_Pwd.Text);
            if (en == null)
                MessageBox.Show("用户名密码错误!");
            else
            {
                if (en.U_STATUS == 1)
                {
                    _bOK = true;
                    Program._nowUser = en;
                    SgArchiveCommons.commons._uname = en.U_ID.ToString();
                    this.Close();
                    
                }
                else
                    MessageBox.Show("此用户已被禁止登录系统!");
            }
        }

        private void btn_Config_Click(object sender, EventArgs e)
        {
            Dialog.Dialog_DBConfig dialog = new Dialog_DBConfig();
            dialog.ShowDialog();
        }

        private void txt_Pwd_KeyDown(object sender, KeyEventArgs e)
        {
            if(e.KeyCode == Keys.Enter)
                btn_Login_Click(new object(), new EventArgs());
        }
    }
}